﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WordpressRestApi;

namespace WordpressDemo.Models
{
    public class SignInViewModel
    {
        /// <summary>Client ID of the Wordpress API.</summary>
        public string ClientID { get; set; }

        /// <summary>Client secret of the Wordpress API.</summary>
        public string ClientSecret { get; set; }

        /// <summary>Authentication code, returned by Wordpress Authentication.</summary>
        public string AuthenticationCode { get; set; }

        /// <summary>Return URL.</summary>
        public string RedirectURL { get; private set; }

        /// <summary>Sets redirect URL from information about the request.</summary>
        /// <param name="request"></param>
        public void SetRedirectUrl(HttpRequestBase request)
        {
            var requestUrl = request.Url.ToString();
            var root = requestUrl.Substring(0, requestUrl.IndexOf('?'));

            RedirectURL = root;
        }
    }
}